<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin:0;padding:0;
        }
        html,body{
            width: 100%; height: 100%; overflow:hidden;
        }
    </style>
</head>
<body>
    <!-- 画布 -->
    <canvas id="canvas"></canvas>

    <script>
        //1. 获取元素
        let canvas = document.querySelector("#canvas");
        //2. 设置宽度和高度『可选』
        canvas.width = document.documentElement.clientWidth;
        canvas.height = document.documentElement.clientHeight;
        //3. 获取画笔对象
        let ctx = canvas.getContext('2d');

        //触摸开始事件
        canvas.addEventListener('touchstart', function(e){
            this.x = e.changedTouches[0].clientX;
            this.y = e.changedTouches[0].clientY;
            //4. 开始绘制
            ctx.beginPath();
            //5. 移动画笔
            ctx.moveTo(this.x, this.y);
        });

        //触摸移动事件
        canvas.addEventListener('touchmove', function(e){
            //6. 绘制线条
            ctx.lineTo(e.changedTouches[0].clientX, e.changedTouches[0].clientY);
            //7. 描边绘制
            ctx.stroke();
        });

    </script>
</body>
</html>